<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

use app\common\model\QuickUser;
use think\Db;

if (!function_exists('formatChapterContent')) {
    /*章节内容格式化格式化为统一格式文本*/
    function formatChapterContent($content,$start,$end)
    {
        $content_new = '';

        if (strlen($content) < 1)
        {
            return $content_new;
        }

        $content = str_replace("\r\n","\n",$content);
        $content = str_replace("\n\n","\n",$content);
        $content = str_replace("<p>","\n",$content);
        $content = str_replace("</p>","\n",$content);

        $list = explode("\n",$content);
        $list_new = '';
        foreach ($list as $k=>$v){

            if( trim($v) ){
                $list_new .= $start.trim($v).$end;
            }
        }
        return $list_new;

    }
}
if (!function_exists('trim_space')) {
    /*清除多余空格*/
    function trim_space($content)
    {
        $content = trim(strip_tags($content));
        $content = preg_replace("/^".chr(194).chr(160)."+/","", $content);
        $content = preg_replace('# #', '', $content);
        $content = removeIllegalChar($content);
        $search  = array(" ", "　", "\t", "\n", "\r", "&nbsp;");
        $replace = array("", "", "", "", "", "");

        return str_replace($search, $replace, $content);
    }
}

if (!function_exists('removeIllegalChar')) {
    /*清除浏览器无法识别的ASCII字符*/
    function removeIllegalChar($content)
    {
        if (is_string($content)) {

            $content = preg_replace("/[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]/", "", $content);

        } else if (is_array($content)) {

            foreach ($content as $k => $v) {
                $content[$k] = removeIllegalChar($v);
            }

        }

        return $content;
    }
}

if (!function_exists('getNonceStr')) {
    /*生成随机字符串*/
    function getNonceStr($length = 32)
    {
        $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
        $str = "";

        for ($i = 0; $i < $length; $i++) {
            $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
        }
        return $str;
    }
}

if (!function_exists('encryptTxt')) {
    function encryptTxt($str)
    {
        $key = '123a45b6d78e90cf'; // 密钥
        $iv = getNonceStr(16); // 初始化向量

        $encrypted = openssl_encrypt($str, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv);
        $encryptedData =  base64_encode($encrypted);

        return ['iv'=>$iv,'encryptedData'=>$encryptedData];
    }
}

if (!function_exists('getFinalIntValue')) {
    /*
     * 获取数字最终值
     * $number 数值
     * */
    function getFinalIntValue($number)
    {
        if(strlen($number) < 1 || $number < 1)
        {
            return 0;
        }

        return $number;
    }
}

if (!function_exists('getQuotient')) {
    /*
     * 两数相除求商
     * $suffer_divisor 被除数
     * $divisor 除数
     * $cm 计算方式
     * $cv 计算值
     * $precision 小数点后精确值
     * */
    function getQuotient($suffer_divisor,$divisor,$precision = 2,$cm = '',$cv = '')
    {
        if($divisor > 0)
        {
            if($cm == 'm')
            {
                return round($suffer_divisor/$divisor*$cv,$precision);
            }
            if($cm == 'd')
            {
                return round($suffer_divisor/$divisor/$cv,$precision);
            }

            return round($suffer_divisor/$divisor,$precision);
        }

        return 0;
    }
}

if (!function_exists('jhCurl')) {
    /*巨量上报请求函数*/
    function jhCurl($url, $params = false, $ispost = 0, $header = false, $cookie_file = false, $timeout = 10)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

        if (is_numeric(strpos($url, 'https'))) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        }

        if ($cookie_file) {
            curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
            curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
        }

        if ($header) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        }

        if ($ispost) {
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            curl_setopt($ch, CURLOPT_URL, $url);
        } else {
            if ($params) {
                curl_setopt($ch, CURLOPT_URL, $url . '?' . $params);
            } else {
                curl_setopt($ch, CURLOPT_URL, $url);
            }
        }

        $response = curl_exec($ch);
        if ($response === FALSE) {
            echo "cURL Error: " . curl_error($ch);
            return false;
        }
        curl_close($ch);
        return $response;
    }
}

if (!function_exists('httpGet')) {
    function httpGet($url)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_URL, $url);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
}

if (!function_exists('isHttpUrl')) {
    //判断是否为http地址
    function isHttpUrl($url)
    {
        $preg = "/^http(s)?:\\/\\/.+/";
        if (preg_match($preg, $url)) {
            return true;
        } else {
            return false;
        }
    }
}

if (!function_exists('checkReadVoucher')) {
    /*
     * 检测消费凭证是否存在
     * */
    function checkReadVoucher($uid,$novel_id,$chapter_no)
    {
        $voucherRedis = new \app\common\classes\VoucherRedis();

        if ($voucherRedis->haveReadVoucher($uid, $novel_id, $chapter_no)) {
            return true;
        }else{

            $where[] = ['uid','=',$uid];
            $where[] = ['novel_id','=',$novel_id];
            $where[] = ['chapter_no','=',$chapter_no];

            $record = Db::table('quick_user_consume_record')->where($where)->field('id')->findOrEmpty();
            if($record)
            {
                $voucherRedis->insertReadVoucher($uid, $novel_id, $chapter_no);//插入消费凭证
                return true;
            }else{
                return false;
            }
        }
    }
}

if (!function_exists('count_word')) {
    /*
     * 计算小说章节字数 20201015
     * 仿word计算字数方式
     * @param $str
     * @return false|int
     */
    function count_word($str)
    {
        //判断是否存在替换字符
        $is_tihuan_count = substr_count($str, "龘");

        try {

            $str = str_replace("<p>", "\r\n", $str);
            $str = str_replace("</p>", "\r\n", $str);
            $str = str_replace("<br>", "\r\n", $str);
            $str = str_replace("<br/>", "\r\n", $str);
            $str = str_replace("\r", "\r\n", $str);
            //先将回车换行符做特殊处理
            $str = preg_replace('/(\r\n+|\s+|　+)/', "龘", $str);
            //处理英文字符数字，连续字母、数字、英文符号视为一个单词
            $str = preg_replace('/[a-z_A-Z0-9-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",\'<>~`\?:;|]/', "m", $str);
            //合并字符m，连续字母、数字、英文符号视为一个单词
            $str = preg_replace('/m+/', "*", $str);
            //去掉回车换行符
            $str = preg_replace('/龘+/', "", $str);

            //返回字数
            return mb_strlen($str) + $is_tihuan_count;

        } catch (\Exception $e) {
            return 0;
        }
    }
}

if (!function_exists('getDayByRange')) {
    function getDayByRange($start, $end)
    {

        $dt_start = strtotime($start);
        $dt_end = strtotime($end);

        $data = [];

        $data[] = (int)date('d', strtotime($start));

        if ($start < $end) {
            do {

                $dt_start = strtotime('+1 day', $dt_start);
                $data[] = (int)date('d', $dt_start);

            } while ($dt_start < $dt_end);
        }

        return $data;
    }
}

if (!function_exists('getDateByRange')) {
    //取得时间范围内日期
    function getDateByRange($start, $end)
    {
        $dt_start = strtotime($start);
        $dt_end = strtotime($end);

        $data = [];

        $data[] = $start;

        if ($start < $end) {
            do {

                $dt_start = strtotime('+1 day', $dt_start);
                $data[] = date('Y-m-d', $dt_start);

            } while ($dt_start < $dt_end);
        }

        return $data;
    }
}

if (!function_exists('getBackhaulTypeTitle')) {
    function getBackhaulTypeTitle($id)
    {
        $title = '';
        $arr = getBackhaulTypeList();

        if (isset($arr[$id])) {
            $title = $arr[$id];
        }

        return $title;
    }
}

if (!function_exists('getBackhaulTypeList')) {
    function getBackhaulTypeList()
    {
        $arr = [1 => '激活', 2 => '付费'];
        return $arr;
    }
}

if (!function_exists('getReportCaliberList')) {
    function getReportCaliberList()
    {
        $arr = [
            1 => '注册X小时内第一笔成功充值，充值金额大于Y元小于Z元的订单',
            2 => '注册当天X小时内第一笔成功充值，充值金额大于Y元小于Z元的订单',
            3 => '注册后X小时内所有成功充值，充值金额大于Y元小于Z元的订单',
            4 => '注册当天X小时内的所有成功充值，充值金额大于Y元小于Z元的订单',
            5 => '上报进入广告X小时内用户首充，充值金额大于Y元小于Z元的订单',
            6 => '上报进入广告当天X小时内用户首充，充值金额大于Y元小于Z元的订单'];
        return $arr;
    }
}

if (!function_exists('getReportCaliberTitle')) {
    function getReportCaliberTitle($id)
    {
        $title = '';
        $arr = getReportCaliberList();

        if (isset($arr[$id])) {
            $title = $arr[$id];
        }

        return $title;
    }
}

if (!function_exists('getDimensionList')) {
    function getDimensionList()
    {
        $arr = [0 => '账号',1 => '媒体', 4 => 'App'];
        return $arr;
    }
}

if (!function_exists('advertMediaList')) {
    function advertMediaList()
    {
        $arr = [1 => '快手', 3 => '巨量二跳', 4 => '百度', 5 => 'UC', 7 => 'OPPO'];
        return $arr;
    }
}

if (!function_exists('getAdvertMediaName')) {
    function getAdvertMediaName($id)
    {
        $title = '无';
        $arr = advertMediaList();

        if (isset($arr[$id])) {
            $title = $arr[$id];
        }

        return $title;
    }
}

if (!function_exists('buildQueryCondition')) {
    /*组装查询条件*/
    function buildQueryCondition($condition, $params)
    {
        $where = [];

        foreach ($condition as $v) {

            $cv = explode(':', $v[2]);

            if (isset($params[$v[3]]) && (
                    ($cv[0] == 'require' && strlen($params[$v[3]]) >= 1) ||
                    ($cv[0] == 'gt' && $params[$v[3]] > $cv[1]) ||
                    ($cv[0] == 'egt' && $params[$v[3]] >= $cv[1]) ||
                    ($cv[0] == 'not_empty' && !empty($params[$v[3]]))
                )) {
                switch ($v[1]) {
                    case "in":
                        $where[] = [$v[0], 'in', $params[$v[3]]];
                        break;
                    case "like":
                        $where[] = [$v[0], 'like', '%' . $params[$v[3]] . '%'];
                        break;
                    case "egt":
                        $where[] = [$v[0], '>=', $params[$v[3]]];
                        break;
                    case "elt":
                        $where[] = [$v[0], '<=', $params[$v[3]]];
                        break;
                    default:
                        $where[] = [$v[0], '=', $params[$v[3]]];
                }
            }

        }

        return $where;
    }
}

/**
 * 返回失败
 * @param $msg
 * @param int $code
 * @return \think\response\Json
 */
function errJson($msg, $code = 0)
{
    return json(['code' => $code, 'msg' => $msg]);
}

/**
 * 返回成功
 * @param array $data
 * @param string $msg
 * @param int $count
 * @return \think\response\Json
 */
function sucJson($data = [], int $count = null)
{
    if ($count === null) {
        return json(['code' => 1, 'msg' => 'ok', 'data' => $data]);
    }
    return json(['code' => 1, 'msg' => 'ok', 'count' => $count, 'data' => $data]);
}


/**
 * 给业务层用，返回格式
 * @param $msg
 * @param int $code
 * @return array
 * @Author: whh
 */
function errArr($msg, $code = 0)
{
    return ['code' => $code, 'msg' => $msg];
}


/**
 * 数据表格格式数据
 * @param array $data
 * @param string $msg
 * @param int $count
 * @return \think\response\Json
 */
function tableJson($data = [], int $count = null)
{
    if ($count === null) {
        return json(['code' => 0, 'msg' => 'ok', 'data' => $data]);
    }
    return json(['code' => 0, 'msg' => 'ok', 'count' => $count, 'data' => $data]);
}


/**
 * 给业务层用，返回格式
 * @param array $data
 * @param int|null $count
 * @return array
 * @Author: whh
 */
function sucArr($data = [], int $count = null)
{
    if ($count === null) {
        return ['code' => 1, 'msg' => 'ok', 'data' => $data];
    }
    return ['code' => 1, 'msg' => 'ok', 'count' => $count, 'data' => $data];
}


/**
 * 请求api
 * @param $url
 * @param int $type
 * @param array $data
 * @return bool|string
 * @Author: whh
 */
if (!function_exists('doCurl')) {
    function doCurl($url, $type = 0, $data = [])
    {
        $ch = curl_init(); // 初始化
        // 设置选项
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        //否则下面curl_exec 报错 ：SSL certificate problem: unable to get local issuer certificate
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        if ($type == 1) {
            // post
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        }
        //执行并获取内容
        $output = curl_exec($ch);
        // 释放curl句柄
        curl_close($ch);
        return $output;
    }
}


/**
 * 清除html获取真实字数
 * @param $str
 * @return int
 * @Author: whh
 */
function clearHtmlGetNum($str)
{
    $str = trim($str); //清除字符串两边的空格
    $str = preg_replace("/\t/", "", $str); //使用正则表达式替换内容，如：空格，换行，并将替换为空。
    $str = preg_replace("/\r\n/", "", $str);
    $str = preg_replace("/\r/", "", $str);
    $str = preg_replace("/\n/", "", $str);
    $str = preg_replace("/ /", "", $str);
    $str = preg_replace("/  /", "", $str);//匹配html中的空格
    return mb_strlen(trim($str), 'UTF-8');
}


/**
 * 判断ip是否被屏蔽，并处理
 * @param $user
 * @param string $ip
 * @return bool true通过 false屏蔽
 * @throws \think\db\exception\DataNotFoundException
 * @throws \think\db\exception\ModelNotFoundException
 * @throws \think\exception\DbException
 */
function ipUnblocked($user, $ip = '')
{
    $res = ipUnblockedRes($user, $ip);
    if ($res === true && $user->ip_blocked != 0) {
        Db::table('quick_user')->where('id', $user->id)->setField('ip_blocked', 0);
        Db::table(QuickUser::fbTable($user->quick_id))->where('id', $user->id)->update([
            'ip_blocked' => 0
        ]);
    } elseif ($res === false && $user->ip_blocked != 1) {
        Db::table('quick_user')->where('id', $user->id)->setField('ip_blocked', 1);
        Db::table(QuickUser::fbTable($user->quick_id))->where('id', $user->id)->update([
            'ip_blocked' => 1
        ]);
    }
    return $res;
}

/**
 * ip屏蔽结果
 * @param $user
 * @param string $ip
 * @return bool
 * @throws \think\db\exception\DataNotFoundException
 * @throws \think\db\exception\ModelNotFoundException
 * @throws \think\exception\DbException
 */
function ipUnblockedRes($user, $ip = '')
{
    if ($user->channel_id && $user->pay_times > 0) {
        //广告用户充值了就不判断地区屏蔽
        return true;
    }
    $klId = Db::table("pay_order_kl_user")->where("uid", $user->id)->value('id');
    if ($user->channel_id && $klId) {
        return true;
    }
    $shield = \think\Db::table("quick_shield")->where("quick_id", $user->quick_id)->find();
    if (!$shield || !$shield['switch']) {
        return true;
    }
    if (!$ip) {
        $ip = request()->ip();
    }
    /**白名单判断*/
    if ($shield['white_uids']) {
        $whiteUidArr = array_filter(explode(',', $shield['white_uids']));
        if (in_array($user->id, $whiteUidArr)) {
            return true;
        }
    }
    /**ip库判断*/
    if ($shield['iplib_ids']) {
        $flag = \think\Db::table("quick_ips")->where('lib_id', 'in', $shield['iplib_ids'])->where("ip", $ip)->find();
        if ($flag) {
            return false;
        }
    }
    /**时间段判断*/
    if ($shield['open_hour']) {
        $openHours = array_filter(explode(',', $shield['open_hour']));
        if (in_array(date("H"), $openHours)) {
            return true;
        }
    }
    $redis = new \app\common\classes\BehaviorRedis();
    $attribution = $redis->getIpAttributionCache($ip);
    if ($attribution === false) {
        $attribution = getIpAttribution($ip);
        if ($attribution) {
            $redis->setIpAttributionCache($ip, $attribution);//添加缓存
        }
    }
    $attribution = json_decode($attribution, true);
    if ($attribution && isset($attribution['data']['city'])) {
        $region = $attribution['data']['region'];
        $city = $attribution['data']['city'];
        $keyword = $region . '-' . $city;
        $areaArr = array_filter(explode(',', $shield['area']));
        if (in_array($region, $areaArr) || in_array($keyword, $areaArr)) {
            //全省或市
            return false;
        }
    }
    return true;
}

/**
 * 获取ip归属地
 * @param $ip
 * @return bool|string
 */
function getIpAttribution($ip)
{
    $host = "https://api01.aliyun.venuscn.com";
    $path = "/ip";
    $method = "GET";
    $appcode = "4010167863bb4ea89f027e168c45a158";
    $headers = array();
    array_push($headers, "Authorization:APPCODE " . $appcode);
    $querys = "ip=" . $ip;
    $bodys = "";
    $url = $host . $path . "?" . $querys;

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_TIMEOUT, 4);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_FAILONERROR, false);

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    if (1 == strpos("$" . $host, "https://")) {
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    }
    $res = curl_exec($curl);
    curl_close($curl);
    return $res;
}


function getDataArr($start_date, $end_date)
{
    // 初始化结果数组
    $dates = array();

    // 将开始日期转换为时间戳
    $current_date = strtotime($start_date);
    $end_date = strtotime($end_date);

    // 循环直到当前日期大于结束日期
    while ($current_date <= $end_date) {
        // 将当前日期添加到结果数组中
        $dates[] = date('Y-m-d', $current_date);

        // 增加一天
        $current_date = strtotime('+1 day', $current_date);
    }
    return $dates;
}


// CURLPOST
function httpPost($url, $data)
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_TIMEOUT, 10);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $tmpInfo = curl_exec($curl);
    if (curl_errno($curl)) {
        return 'Errno' . curl_error($curl);
    }
    curl_close($curl);
    return $tmpInfo;
}


if (!function_exists('get_phone_brand')) {
    function get_phone_brand($ua)
    {
        $user_agent = $ua;
        if (stripos($user_agent, "iPhone") !== false) {
            $brand = 'iPhone';
        } else if (stripos($user_agent, "SAMSUNG") !== false || stripos($user_agent, "Galaxy") !== false || strpos($user_agent, "GT-") !== false || strpos($user_agent, "SCH-") !== false || strpos($user_agent, "SM-") !== false) {
            $brand = '三星';
        } else if (stripos($user_agent, "Huawei") !== false || stripos($user_agent, "Honor") !== false || stripos($user_agent, "H60-") !== false || stripos($user_agent, "H30-") !== false) {
            $brand = '华为';
        } else if (stripos($user_agent, "Lenovo") !== false) {
            $brand = '联想';
        } else if (strpos($user_agent, "MI-ONE") !== false || strpos($user_agent, "MI 1S") !== false || strpos($user_agent, "MI 2") !== false || strpos($user_agent, "MI 3") !== false || strpos($user_agent, "MI 4") !== false || strpos($user_agent, "MI-4") !== false) {
            $brand = '小米';
        } else if (strpos($user_agent, "HM NOTE") !== false || strpos($user_agent, "HM201") !== false) {
            $brand = '红米';
        } else if (stripos($user_agent, "Coolpad") !== false || strpos($user_agent, "8190Q") !== false || strpos($user_agent, "5910") !== false) {
            $brand = '酷派';
        } else if (stripos($user_agent, "ZTE") !== false || stripos($user_agent, "X9180") !== false || stripos($user_agent, "N9180") !== false || stripos($user_agent, "U9180") !== false) {
            $brand = '中兴';
        } else if (stripos($user_agent, "OPPO") !== false || strpos($user_agent, "X9007") !== false || strpos($user_agent, "X907") !== false || strpos($user_agent, "X909") !== false || strpos($user_agent, "R831S") !== false || strpos($user_agent, "R827T") !== false || strpos($user_agent, "R821T") !== false || strpos($user_agent, "R811") !== false || strpos($user_agent, "R2017") !== false) {
            $brand = 'OPPO';
        } else if (strpos($user_agent, "HTC") !== false || stripos($user_agent, "Desire") !== false) {
            $brand = 'HTC';
        } else if (stripos($user_agent, "vivo") !== false) {
            $brand = 'vivo';
        } else if (stripos($user_agent, "K-Touch") !== false) {
            $brand = '天语';
        } else if (stripos($user_agent, "Nubia") !== false || stripos($user_agent, "NX50") !== false || stripos($user_agent, "NX40") !== false) {
            $brand = '努比亚';
        } else if (strpos($user_agent, "M045") !== false || strpos($user_agent, "M032") !== false || strpos($user_agent, "M355") !== false) {
            $brand = '魅族';
        } else if (stripos($user_agent, "DOOV") !== false) {
            $brand = '朵唯';
        } else if (stripos($user_agent, "GFIVE") !== false) {
            $brand = '基伍';
        } else if (stripos($user_agent, "Gionee") !== false || strpos($user_agent, "GN") !== false) {
            $brand = '金立';
        } else if (stripos($user_agent, "HS-U") !== false || stripos($user_agent, "HS-E") !== false) {
            $brand = '海信';
        } else if (stripos($user_agent, "Nokia") !== false) {
            $brand = '诺基亚';
        } else {
            $brand = '其他手机';
        }
        return $brand;
    }
}